<template>
    <div>

    </div>
</template>

<script>
  import { ajax } from "@/store/yg/common/utils";

    export default {
        data() {
            return {};
        },

        methods: {
          async check() {
            //获取选中的行
            const ids = this.$store.state.edit.ids;
            const selectedData = this.$store.state.main.selectedData;
            if (selectedData.length < 1) {
              this.$message.error("请至少勾选1条记录！");
              return;
            }
            //校验：只能提交草稿状态的申请单
            for (let i = 0; i < selectedData.length; i++) {
              let item = selectedData[i];
              if(item.approveStatus != 0){
                this.$message.error("只能提交草稿状态的申请单！");
                return;
              }
            }
            //请求后台
            const { code, data, message } = await ajax("commit", {
              ids: ids
            });
            if (code !== 200) {
              if (message) {
                this.$message.error(message);
              } else {
                this.$message.error("服务器异常");
              }
              return;
            }
            this.$message({
              type: "success",
              message: "提交成功！"
            });
          }
        },

        mounted() {
          this.check();
        }
    };
</script>


<style>

</style>
